#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+5,M = 15;
int t,n,m;
int A[N],a[N],c[N];
string d[N];
int x[4];
int b[N];


int main(){
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) cin >> A[i];
	for(int i = 1; i <= m; ++i) cin >> c[i];
	int K = 0;
	while((1 << K) < n) K++;
	for(int i = K; i >= 1; i++){
		cin >> d[i];
	}
	cin >> t;
	while(t--){
		for(int i = 0; i < 4; ++i) cin >> x[i];
		for(int i = 1; i <= n; ++i) a[i] = A[i]^x[i%4];
		for(int i = 1; i <= m; ++i){
			int k = 0;
			while(1<<k < c[i]) k++;
			for(int i = 1; i <= k; ++i){
				for(int j = 1; j <= 1<<i; j += 2){
					if(d[k][j/2] == '0')
				}
			}
		}
	}

	
	return 0;
}
